package com.dongdongshop.data;

import com.dongdongshop.constant.ResultConstant;
import com.dongdongshop.enums.ResultEnum;

import javax.xml.ws.Response;
import java.util.List;

public class Result<T> {
    private Integer code;//返回状态码 比如10000 表示成功
    private String message;//返回提示信息 比如:参数为空,用户未登录 权限不足
    private T data;//返回的数据


    public static Result OK(){
        return new Result(ResultConstant.SUCCESS_CODE,ResultConstant.SUCCESS_MESSAGE);
    }
    public static Result ER(){
        return new Result(ResultConstant.ERROR_CODE,ResultConstant.ERROR_MESSAGE);
    }
    public static Result response(ResultEnum em){
        return new Result(em.getCode(),em.getMessage());
    }

    public Result() {
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }
}
